import { Controller, Get, Post, Query, Body } from '@nestjs/common';
import { AppService } from './app.service';

@Controller('/app')
export class AppController {
  constructor(private readonly appService: AppService) {}

  /**
   * 测试普通 get 请求
   * @api: http://localhost:3000/app/hello
   */
  @Get('/hello')
  getHello(): string {
    return this.appService.getHello();
  }

  /**
   * 测试携带参数的 get 请求
   * @api: http://localhost:3000/app/param?id=1
   */
  @Get('param')
  getParam(@Query('id') id: string): any {
    console.log('id', id);
    return `传递的id参数为${id}`;
  }

  /**
   * 普通post请求
   * @api: http://localhotst:3000/app/p
   */
  @Post('p')
  createApp(): any {
    return {
      code: 200,
      msg: 'success',
      data: null,
    };
  }

  /**
   * 测试携带参数的post请求
   * @api: http://localhost:3000/app/param.p
   */
  @Post('param.p')
  addApp(@Body() param: any): any {
    return {
      code: 200,
      msg: 'success',
      data: param,
    };
  }
}
